package com.dotstone.chipism.activity;


import com.dotstone.chipism.R;
import com.dotstone.chipism.util.SPUtils;
import com.dotstone.chipism.util.ToastShow;
import com.dotstone.chipism.view.slidingfragmenu.BarUtils;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class AccountActivity extends BaseActivity {
	private LinearLayout mBackL;
	private Button mFinishB;
	private TextView mUsernameTv;
//	private EditText mNameed;
	private EditText mNicknameEd;
//	private EditText mIdEd;
//	private EditText mAddressed;
//	private TextView mHouseTv;
	private Button mResetPwdB;
	private TextView mStatusBar;
	private String phone;
//	private String address = "";
	private String name = "";
//	private String userCard ="";
	private String userName = "";
	private TextView more_tv;
//	private LinearLayout mHouseL;

	@Override
	public void widgetClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back_layout:
			finish();
			break;
		case R.id.reset_pwd_btn:
			ToastShow.Show(getApplicationContext(), "善待完善");
			break;
		case R.id.nextstep:
			name = mNicknameEd.getText().toString();
			userName = mUsernameTv.getText().toString();
//			if(name.length()<=8||name.length()>=3){
//				uploadInfo();
//			}else{
//				ToastShow.Show(getApplicationContext(), "用户名长度为3-8位");
//			}
			ToastShow.Show(getApplicationContext(), "善待完善");
			break;
		case R.id.more_tv:
			 ToastShow.Show(getApplicationContext(), "善待完善");
			 Intent intent2 = new Intent(getApplicationContext(),AccountActivity1.class);
		     startActivity(intent2);
		//	Intent intent11 = new Intent(getApplicationContext(), ElectryStatisticActivity.class);
			//startActivity(intent11);
			break;
		default:
			break;
		}
	}

	@Override
	public void initParms(Bundle parms) {
		// TODO Auto-generated method stub

	}

	@Override
	public View bindView() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int bindLayout() {
		// TODO Auto-generated method stub
		return R.layout.activity_account;
	}

	@Override
	public void initView(View view) {
		// TODO Auto-generated method stub
		mBackL = $(R.id.back_layout);
		mFinishB = $(R.id.nextstep);
		mFinishB.setText(getString(R.string.finish));
		mFinishB.setVisibility(View.INVISIBLE);
		mResetPwdB = $(R.id.reset_pwd_btn);
		mStatusBar = $(R.id.tv_statusBar_mian);
		mUsernameTv = $(R.id.username_tv);
		phone = (String)SPUtils.get(getApplicationContext(), "user_name", "");
		mUsernameTv.setText(phone);
//		mNameed = $(R.id.name_ed);
		mNicknameEd = $(R.id.nickname_edit);
		more_tv = $(R.id.more_tv);
		String nickname = (String)SPUtils.get(getApplicationContext(), "nickname", "");
		mNicknameEd.setText(nickname);
//		mIdEd = $(R.id.credit_ed);
//		mAddressed = $(R.id.address_ed);
		boolVersion();
		mBackL.setOnClickListener(this);
		mResetPwdB.setOnClickListener(this);
		mFinishB.setOnClickListener(this);
		more_tv.setOnClickListener(this);
//		getInfo();
	}
	
//	private void uploadInfo(){
//			RequestParams params = new RequestParams(HttpURL.UPLOAD_INFO_URL);
//			params.setAsJsonContent(true);
//			JSONObject obj = new JSONObject();
//			try {
//				obj.put("address", "广东省深圳市宝安区");
//				obj.put("name", name);
//				obj.put("userCard", "123456789987654321");
//				obj.put("userName", userName);
//				obj.put("key", "10000");
//				obj.put("token", (String) SPUtils.get(getApplicationContext(),
//						"token", ""));
//				obj.put("requestTime", "" + System.currentTimeMillis());
//				Log.d("test", "update user = " + obj.toString());
//			} catch (JSONException e1) {
//				e1.printStackTrace();
//			}
//			params.setBodyContent(obj.toString());
//
//			x.http().post(params, new Callback.CommonCallback<String>() {
//				@Override
//				public void onSuccess(String result) {
//					Log.e("Tag", "成功=" + result);
//					try {
//						JSONObject jsonObject = new JSONObject(result);
//
//						int resultCode = jsonObject.optInt("resultCode");
//						if (resultCode == 1) {
//							ToastShow.Show(AccountActivity.this,getString(R.string.uploadsuccess));
//							SPUtils.put(getApplicationContext(), "nickname", name);
//							UserFragment.instance.mUserNameT.setText(name);
//							finish();
//							
//						} else {
//							String errorMsg = jsonObject.getString("errorMsg");
//							ToastShow.Show(AccountActivity.this, errorMsg);
//							throw new Exception();
//						}
//					} catch (Exception e) {
//						e.printStackTrace();
//					}
//				}
//
//				@Override
//				public void onError(Throwable ex, boolean isOnCallback) {
//					Log.e("Tag", "错误" + ex.getMessage());
//				}
//
//				@Override
//				public void onCancelled(CancelledException cex) {
//
//				}
//
//				@Override
//				public void onFinished() {
//					Log.e("Tag", "完成");
//				}
//			});
//		
//	}

	public void boolVersion() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

			Window window = getWindow();
			window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			// 透明导航栏
			getWindow().addFlags(
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
			// 改变titlebar的高度
			int statusbarHeight = BarUtils.getStatusBarHeight(this);
			RelativeLayout.LayoutParams layoutParams1 = (RelativeLayout.LayoutParams) mStatusBar
					.getLayoutParams();
			layoutParams1.height = statusbarHeight;
			mStatusBar.setLayoutParams(layoutParams1);
			mStatusBar.setVisibility(View.VISIBLE);
		} else {
			mStatusBar.setVisibility(View.GONE);
		}
	}

	@Override
	public void setListener() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doBusiness(Context mContext) {
		// TODO Auto-generated method stub

	}

}
